class Solution {
public:
    string longestPalindrome(string s)
    {
        int n = s.size();
        vector<vector<bool>> dp(n, vector<bool>(n));
        int begin = -1, len = 0;

        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = i; j < n; j++)
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j && s[i] == s[j]) dp[i][j] = true;
                else
                {
                    if (s[i] == s[j]) dp[i][j] = dp[i + 1][j - 1];
                }
                if (dp[i][j] == true && j - i + 1 > len)
                {
                    begin = i;
                    len = j - i + 1;
                }
            }
        }
        return s.substr(begin, len);
    }
};
class Solution {
public:
    int countSubstrings(string s)
    {
        int n = s.size();
        vector<vector<bool>> dp(n, vector<bool>(n));
        int ret = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = i; j < n; j++)
            {
                if (i == j) dp[i][j] = true;
                else if (i + 1 == j && s[i] == s[j]) dp[i][j] = true;
                else
                {
                    if (s[i] == s[j]) dp[i][j] = dp[i + 1][j - 1];
                }
                if (dp[i][j]) ret++;
            }
        }
        return ret;
    }
};
class Solution {
public:
    int findNumberOfLIS(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> len(n);
        vector<int> count(n);
        len[0] = count[0] = 1;

        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (nums[i] > nums[j])
                {
                    if (len[j] + 1 == len[i])
                    {
                        count[i] += count[j];
                    }
                    else if (len[j] + 1 > len[i])
                    {
                        len[i] = len[j] + 1;
                        count[i] = count[j];
                    }
                }
            }
        }

    }
};